﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class Marriage : IEquatable<Marriage>
    {
        public void ImportList(List<Classes.Marriage> marList)
        {
            var mdb = new MedregDBDataContext();
            var ListMar = new List<Marriage>();
            foreach (var mar in marList)
            {
                Marriage mar1 = new Marriage() { ID = mar.ID, Name = mar.Name };
                Marriage query;

                if (mdb.Marriage.LongCount() == 0)
                {
                    mdb.Marriage.InsertOnSubmit(mar1);
                }
                else
                {
                    try
                    {
                        query = mdb.Marriage.Single(l => l.ID == mar1.ID);
                        query.Name = mar1.Name;

                    }
                    catch (ArgumentNullException e)
                    {
                    }
                    catch (InvalidOperationException e)
                    {

                        if (!ListMar.Contains(mar1))
                        {
                            mdb.Marriage.InsertOnSubmit(mar1);
                            ListMar.Add(mar1);
                        }
                    }
                }
            }
            mdb.SubmitChanges();
        }
        public bool Equals(Marriage other)
        {
            var i = this.ID.Equals(other.ID);
            var j = this.Name.Equals(other.Name);
            if (i & j)
            {
                return true;
            }
            return false;
        }
    }
}
